package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping()
    @ApiOperation("新增分类")
    public Result save(@RequestBody CategoryDTO categoryDTO){
        return categoryService.save(categoryDTO);
    }
    @PutMapping
    @ApiOperation("修改分类")
    public Result<String> updateCategory(@RequestBody CategoryDTO categoryDTO){

        return categoryService.update(categoryDTO);
    }
        @PostMapping ("/status/{status}")
    @ApiOperation("启用禁用分类")
    public Result updateStatus(@PathVariable Integer status ,Long id){
        return categoryService.updateStatus(status,id);
    }
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO){

        return categoryService.pageQuery(categoryPageQueryDTO);
    }
    @GetMapping("/list")
    @ApiOperation("根据类型查询")
    public Result<List<Category>> list(Integer type){
        return categoryService.list(type);
    }
    @DeleteMapping
    @ApiOperation("根据id删除分类")
    public Result deleteById(Long id){
        return categoryService.deleteById(id);
    }
}
